package com.xgc.oauth.controller;

import com.xgc.oauth.utils.JwtUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException;

/**
 * oauth2
 *
 * @author xgc
 * @date 2024/01/08
 */
@RestController
@RequestMapping("/oauth")
public class Oauth2Controller {

    @GetMapping("/login")
    public String login() throws NoSuchAlgorithmException, InvalidKeySpecException {
        return JwtUtil.create(2, 60*60);
    }

    @GetMapping("/other")
    public String other(){
        return "other";
    }

    @RequiresPermissions("sys:perm:read")
    @GetMapping("/permRead")
    public String permRead() {
        return "授权:读";
    }

    @RequiresPermissions("sys:perm:write")
    @GetMapping("/permWrite")
    public String permWrite() {
        return "授权:写";
    }

    @RequiresRoles("系统管理员")
    @GetMapping("/roleSys")
    public String roleSys() {
        return "授权:系统管理员";
    }

    @RequiresRoles("普通管理员")
    @GetMapping("/roleCom")
    public String roleCom() {
        return "授权:普通管理员";
    }
}
